package animals;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.time.LocalDate;

enum Colors {
  Red, Blue, Green,
  Yellow,
}

public class MyFirstJavaProgram {
  public static void main(String []args) {

    // Variables
    // String words = "hello james hardorn";
    // int count = 0;
    // double[] arr = new double[10];

    // System.out.println(words);
    // System.out.println(count);

    // MyDog dog_tom = new MyDog("Jim");
    // dog_tom.run();
    // dog_tom.sayBob();
    // dog_tom.calculate();

    // System.out.println( dog_tom.nickName);
    
    // System.out.println("what is the dog's name? " + dog_tom.name);
    
    // 单例模式
    // System.out.println("-------------------------");
    // VirtualWorld world = VirtualWorld.getInstance();
    // world.startSun();

    // VirtualWorld world1 = VirtualWorld.getInstance();
    // world1.startRain();

    System.out.println("-------------------------");
    // System.out.println(words.matches("hello(.*)"));
    // System.out.println(arr);

    // for (int i = 0; i < arr.length; i++) {
    //   System.out.println(arr[i]);
    // }

    // 数组
    // String[] nameArr = {"Jame", "Jim", "Jimmy"};
    
    // for (String name : nameArr) {
    //   System.out.println(name);
    // }

    // 日期时间
    // DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    // String dateStr = "2024-08-01 09:48:47";
    // LocalDateTime date2 = LocalDateTime.parse(dateStr, dtf);
    // LocalDateTime dateBefore = LocalDateTime.now();
    // System.out.println(date2.getMonthValue());
    // System.out.println(date2.getYear());
    // System.out.println(date2.isBefore(dateBefore));
    // LocalDateTime yesterDay = LocalDateTime.now().minusDays(1);
    // System.out.println(yesterDay.format(formater));

    //--------------------------------
    // String input = "Tom 77 is a very good girl like 12";
    // String pattern = "[0-9]+";
    // Pattern r = Pattern.compile(pattern);
    // Matcher m = r.matcher(input);
    // while (m.find()) {
    //   System.out.println(m.group(0));
    // }

    //-----------
    // file
    // String filePath = "D:\\my-project\\n" + //
    //         "etwork basic learn\\n" + //
    //         "etwork-basic\\java-demo\\launch.json";
    
            // File inputFile = new File(filePath);
            // System.out.println(inputFile.isDirectory());
            // System.out.println(inputFile.isFile());
            // InputStream f = new FileInputStream(inputFile);
    // read/write file

    // try {
    //   FileInputStream fis = new FileInputStream("./launch.json");
      
    //   DataInputStream dis = new DataInputStream(fis);

    //   int data;
    //   String files = "";
    //   while ((data = dis.read()) != -1) {
    //     files += Character.toString((char) data);
    //   }
    //   System.out.print(files);
    //   Files.write(Paths.get("./write.json"), files.getBytes());

    // } catch (IOException e) {
    //   e.printStackTrace();
    // }

    // enum
    System.out.println(Colors.Red);
  }
}

class BaseDog {
  String name = "";
  protected String type = "dot";
  String color = "black";

  public BaseDog(String name) {
    this.name = name;
  } 

  void run() {
    String words = String.format("%s is running", this.name);
    System.out.println(words);
  }
}

/** 继承  */
class MyDog extends BaseDog {

  final String nickName = "Jame";

  public MyDog(String name) {
    super(name);
  }

  void sayBob() {
    this.sayPerpleWords();
    System.out.println(type);
    System.out.println("-----------");
    System.out.println(color);
    System.out.println("-----------");

  }

  private void sayPerpleWords() {
    System.out.println("Perple words");
  }

  void calculate() {
    Integer a = 2;
    String b = "lick";
    // StringBuffer buffer = new StringBuffer();
    // buffer.append("hello");
    // String [] arr = {"a", "b", "c"};

    // for(String name: arr) {
    //   System.out.println(name);
    // }

    // while (a < 8) {
    //   a ++;
    //   if (a >= 6) {
    //     continue;
    //   }
    //   System.out.println(a);
    // }

    // System.out.println(a.compareTo(3));

    // System.out.println(Character.isLetter('a'));

    // System.out.println(buffer.delete(0, 2));

    // System.out.println(b.startsWith("l"));


  }
}

/** 单例模式 */
class VirtualWorld {

  private String weather = "sun";

  private static VirtualWorld world = null;

  private VirtualWorld() {
    System.out.println("VirtualWorld is created");
  }

  public static VirtualWorld getInstance() {
    System.err.println(world);
    if (world == null) {
      world = new VirtualWorld();
    }

    return world;
  }

  public void startRain() {
    System.out.println(world.weather);
    this.weather = "rain";
    System.out.println("The world start rain");
  }

  public void startSun() {
    System.err.println(world.weather);
    this.weather = "sun1";
    System.out.println("The world start sun");
  }
}